package com.kupurui.asteacher.ui.mine;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.UserInfo;
import com.kupurui.asteacher.http.Teacher;
import com.kupurui.asteacher.ui.BaseFgt;
import com.kupurui.asteacher.ui.mine.message.MessageAty;
import com.kupurui.asteacher.ui.mine.person.PersonalInformationAty;
import com.kupurui.asteacher.ui.mine.setting.SettingAty;
import com.kupurui.asteacher.utils.UserManger;

import butterknife.Bind;
import butterknife.OnClick;
import cn.sharesdk.onekeyshare.OnekeyShare;
import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by Administrator on 2017/7/17.
 */

public class MineFgt extends BaseFgt {

    @Bind(R.id.imgv_setting)
    ImageView imgvSetting;
    @Bind(R.id.imgv_message)
    ImageView imgvMessage;
    @Bind(R.id.imgv_head)
    SimpleDraweeView imgvHead;
    @Bind(R.id.tv_mine_nick)
    TextView tvMineNick;
    @Bind(R.id.tv_mine_phone)
    TextView tvMinePhone;
    @Bind(R.id.relatively_information)
    RelativeLayout relativelyInformation;
    @Bind(R.id.tv_mine_share)
    TextView tvMineShare;
    @Bind(R.id.tv_mine_about)
    TextView tvMineAbout;

    @Override
    public int getLayoutId() {
        return R.layout.mine_fgt;
    }

    @Override
    public void initData() {
        imgvHead.setImageURI(UserManger.getUserInfo().getImg());
        tvMineNick.setText(UserManger.getUserInfo().getName()+"老师");
        tvMinePhone.setText(UserManger.getUserInfo().getPhone());
    }

    @Override
    public void requestData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        new Teacher().center(UserManger.getId(),this,0);
    }

    @OnClick({R.id.imgv_setting,R.id.imgv_message,R.id.relatively_information,R.id.tv_mine_about,R.id.tv_mine_share})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.imgv_setting://设置
                startActivity(SettingAty.class,null);
                break;
            case R.id.imgv_message://消息
                startActivity(MessageAty.class,null);
                break;
            case R.id.relatively_information://个人资料
                startActivity(PersonalInformationAty.class,null);
                break;
            case R.id.tv_mine_about://关于我们
                startActivity(AboutAty.class,null);
                break;
            case R.id.tv_mine_share:
                showShare();
                break;
        }
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what){
            case 0:
                UserInfo userInfo = AppJsonUtil.getObject(result,UserInfo.class);
                UserManger.setUserInfo(userInfo);
                imgvHead.setImageURI(UserManger.getUserInfo().getImg());
                tvMineNick.setText(UserManger.getUserInfo().getName());
                tvMinePhone.setText(UserManger.getUserInfo().getPhone());
                break;
        }
        super.onSuccess(result, call, response, what);
    }

    private void showShare() {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
        // 分享时Notification的图标和文字  2.5.9以后的版本不     调用此方法
        //oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
        oks.setTitle("数数君教师");
        // titleUrl是标题的网络链接，仅在人人网和QQ空间使用
        oks.setTitleUrl("http://www.usiku.cn/download/teacher.html");
        // text是分享文本，所有平台都需要这个字段
        oks.setText("数数君教师端,快来试试吧");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
//        oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        oks.setImageUrl("http://usiku.cn/uploads/img/20170912/9752c0c1f6948826cf44fb9a7b675020.png");
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl("http://www.usiku.cn/download/teacher.html");
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite(getString(R.string.app_name));
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl("http://www.usiku.cn/download/teacher.html");

        // 启动分享GUI
        oks.show(getActivity());
    }
}
